﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;

namespace nr.GLV.Windows.Controls
{
    public class FilterInfo : System.Windows.Forms.TreeNode
    {
        public FilterField Field { get; set; }
        public FilterOperator Operator { get; set; }
        public string ValueToCompare { get; set; }

        public string Filter
        {
            get { return string.Format(Field.FilterText, Operator.Value, ValueToCompare); }
        }

        public override string ToString()
        {
            return string.Format(Field.FilterFriendlyFormat, Operator.Text, ValueToCompare);
        }

        public FilterInfo() { Field = null; Operator = null; ValueToCompare = string.Empty; }

        public FilterInfo(SerializationInfo si, StreamingContext context)
            : base(si, context)
        {
            Field = (FilterField)si.GetValue("field", typeof(FilterField));
            Operator = (FilterOperator)si.GetValue("operator", typeof(FilterOperator));
            ValueToCompare = si.GetString("value");
        }

        protected override void Serialize(SerializationInfo si, StreamingContext context)
        {
            base.Serialize(si, context);

            si.AddValue("field", Field, typeof(FilterField));
            si.AddValue("operator", Operator, typeof(FilterOperator));
            si.AddValue("value", ValueToCompare);
        }
    }
}
